// pages/deposit/payCenter/index.js
const service = require("../../../service/member");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    selectId: null,
    money: 0,
    giveMoney: 0
  },

  selectMoney(e) { // 选择金钱
    let {
      id
    } = e.currentTarget.dataset;
    this.setData({
      selectId: id,
      money: e.currentTarget.dataset.datas.money,
      giveMoney: e.currentTarget.dataset.datas.giveMoney
    })
    console.log(e)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    service.getpaylist({
      "queryRequest": {
        "page": "1",
        "size": "1000"
      }

    }, res => {
      console.log(res)
      if (res.code == "00000") {
        if (res.data.records.length != 0) {
          this.setData({
            list: res.data.records
          })
        }
      }
    })
  },
  rechargeTo() {
    service.memberPay({
      type : 1,
      openId: wx.getStorageSync("userInfo").openId,
      money: this.data.money,
      giveMoney: this.data.giveMoney,
      customerId: wx.getStorageSync("userInfo").id
    }, res => {
      wx.requestPayment({
        appId: res.data.appId,
        timeStamp: res.data.timeStamp,
        nonceStr: res.data.nonceStr,
        package: res.data.package,
        signType: res.data.signType,
        paySign: res.data.sign,
        success(res) {
          console.log(res);
          wx.showToast({
            title: '充值成功',
            icon:'success',
            duration:2000
          })
          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/deposit/vip/index',
            })
          }, 1000);
        },
        fail(res) {
          wx.showToast({
            title: '充值失败',
            icon:'none',
            duration:2000
          })
         
        }
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})